//
//  ViewController.m
//  UI_24_Animation
//
//  Created by 李劲成 on 16/4/17.
//  Copyright © 2016年 ljc. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *ViewOfOrange;
@property (weak, nonatomic) IBOutlet UIView *ViewOfRed;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 知识点1: UIView实现动画(1/2)
- (IBAction)handleView:(id)sender {
    
//     API 1:  仅带动画效果
//    [UIView animateWithDuration:2.0 animations:^{
//        // 设置控件的属性值.
//        self.ViewOfOrange.frame = CGRectMake(0, 300, self.view.frame.size.width, 128);
//        self.ViewOfOrange.backgroundColor = [UIColor redColor];
//    }];
    
    // API 2:  动画效果 和 完成效果
//    [UIView animateWithDuration:2.0 animations:^{
//        self.ViewOfOrange.frame = CGRectMake(0, 300, self.view.frame.size.width, 128);
//        self.ViewOfOrange.backgroundColor = [UIColor redColor];
//    }completion:^(BOOL finished) {
//        self.ViewOfOrange.backgroundColor = [UIColor orangeColor];
//    }];
    
    // API 3: options 参数 控制动画效果.
//    [UIView animateWithDuration:2.0 delay:1.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
//        self.ViewOfOrange.frame = CGRectMake(0, 300, self.view.frame.size.width, 128);
//        self.ViewOfOrange.backgroundColor = [UIColor redColor];
//    } completion:^(BOOL finished) {
//        
//    }];
//    
    // API 4: usingSpringWithDamping 震荡效果 initialSpringVelocity 初始速度
    [UIView animateWithDuration:2.0 delay:1.0 usingSpringWithDamping:0.7 initialSpringVelocity:1 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
        
        self.ViewOfOrange.frame = CGRectMake(0, 300, self.view.frame.size.width, 128);
        
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark - 知识点2: UIView动画2
- (IBAction)View2:(id)sender {
    
//    // 准备开始动画
//    [UIView beginAnimations:@"abc" context:nil];
//    // 设置动画参数
//    // 持续时间
//    [UIView setAnimationDuration:2.0];
//    //循环次数
//    [UIView setAnimationRepeatCount:CGFLOAT_MAX];
//    // 自动保留
//    [UIView setAnimationRepeatAutoreverses:YES];
//    // 控件属性的更改
//    self.ViewOfOrange.frame = CGRectMake(0, 300, self.view.frame.size.width, 128);
//    self.ViewOfOrange.backgroundColor = [UIColor redColor];
//    // 提交动画.
//    [UIView commitAnimations];
    
#pragma mark - 知识点3: CABasicAnimation
//    CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
//    // 开始值.
//    basic.fromValue = @1;
//    // 目标值.
//    basic.toValue = @0.5;
//    
//    basic.duration = 1;
//    basic.autoreverses = YES;
//    basic.repeatCount = CGFLOAT_MAX;
//    
//    // layer层上添加动画.
//    [self.ViewOfOrange.layer addAnimation:basic forKey:@"basic"];
    
#pragma mark - 知识点4: CAAnimationGroup
//    // 创建动画组对象.
//    CAAnimationGroup *group = [CAAnimationGroup animation];
//    
//    // 创建基础动画效果.
//    CABasicAnimation *basic1 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
//    basic1.fromValue = @1;
//    basic1.toValue = @0.2;
//    
//    CABasicAnimation *basic2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//    basic2.fromValue = @0;
//    basic2.toValue = @M_PI;
//    
//    // 添加动画效果至动画组
//    group.animations = @[basic1, basic2];
//    group.duration = 2;
//    group.autoreverses = YES;
//    group.repeatCount = CGFLOAT_MAX;
//    
//    
//    // layer层添加动画对象.
//    [self.ViewOfOrange.layer addAnimation:group forKey:@"group"];
//    
#pragma mark - 知识点5: CAKeyFrameAnimation
//    // 创建动画对象
//    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//    
//    // 设置动画的API
//    
//    // 通过函数创建CGPathRef结构体.
//    CGMutablePathRef path = CGPathCreateMutable();
//    
//    // 起始点
//    CGPathMoveToPoint(path, nil, self.ViewOfRed.center.x, self.ViewOfRed.center.y);
//    
//    // 路径经过的点(直线移动).
//    //    CGPathAddLineToPoint(path, nil, 200, 200);
//    //    CGPathAddLineToPoint(path, nil, 200, 300);
//    //    CGPathAddLineToPoint(path, nil, 300, 300);
//    
//    
//    // 路径经过的点(曲线移动).
//   CGPathAddCurveToPoint(path, nil,self.ViewOfRed.center.x, self.ViewOfRed.center.y, self.ViewOfRed.center.x - 10, self.ViewOfRed.center.y + 50, self.ViewOfRed.center.x + 100, self.ViewOfRed.center.y + 100);
//
//    
//    keyFrame.path = path;
//    keyFrame.duration = 2;
//    keyFrame.autoreverses = YES;
//    keyFrame.repeatCount = CGFLOAT_MAX;
//    
//    // layer层添加动画.
//    [self.ViewOfRed.layer addAnimation:keyFrame forKey:@"keyFrame"];

#pragma mark - 知识点6: CATransition
    // 创建动画对象.
    CATransition *sition = [CATransition animation];
    
    // 设置动画API
    sition.type = @"cameraIrisHollowOpen";
    
    sition.duration = 2;
    sition.autoreverses = YES;
    sition.repeatCount = CGFLOAT_MAX;
    
    
    // layer上添加动画.
    [self.ViewOfOrange.layer addAnimation:sition forKey:@"sition"];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
